<?php
/*
 * 2021/7/15
 * 22:00
 * User: 2650332702@qq.com
 */
namespace App\Api\Manages;


use App\Api\Bases\BaseController;
use App\Api\Services\JsonService;

class CommonController extends BaseController
{
    //分页数据重构
    public function PagingData($pagedata = [])
    {
        if(!is_array($pagedata)) $pagedata = $pagedata->toArray();
        if(empty($pagedata)){
            return JsonService::fail('数据不完整');
        }
        foreach ($pagedata['data'] as &$once){
            $once['start_time'] = date('Y-m-d H:i:s',$once['start_time']);
            $once['end_time'] = date('Y-m-d H:i:s',$once['end_time']);
            $once['percentage']=round(($once['paid_num']/$once['stock'])*100);
        }
        $data = [
            'current_page'=>$pagedata['current_page'],
            'data'=>$pagedata['data'],
            'total_pages'=>$pagedata['last_page'],
            'total_data'=>$pagedata['total'],
            'current_data'=>$pagedata['per_page']
        ];
        return JsonService::success($data);
    }
}
